package com.wuzuqing.android.eightdiagrams.utils;


import com.wuzuqing.android.eightdiagrams.model.TermModel;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * 〈将日期转换为干支历法的年月日时，并计算生肖、阴历、星期几〉
 *
 * @author wgn
 * @create 2018/6/29
 */
public class Birth {

    int[] lunarInfo = new int[]{0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260,
            0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6,
            0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0,
            0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54,
            0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, 0x0d4a0, 0x0ea50,
            0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,
            0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0,
            0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0,
            0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6,
            0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950,
            0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4,
            0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6, 0x095b0, 0x049b0,
            0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60,
            0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58,
            0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, 0x0d954, 0x0d4a0,
            0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,
            0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0,
            0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52,
            0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0,
            0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250,
            0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577,
            0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, 0x14b63};
    public static   String[] Gan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬",
            "癸","未知"};

    public static  String[] Zhi = new String[]{
            "子",    // 23-01
            "丑",    //01-03
            "寅",    //03-05
            "卯",    //05-07
            "辰",    //07-09
            "巳",    //09-11
            "午",    //11-13
            "未",    //13-15
            "申",    //15-17
            "酉",    //17-19
            "戌",    //19-21
            "亥"     //21-23
    };
    long[] sTermInfo = new long[]{0, 21208, 42467, 63836, 85337, 107014,
            128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989,
            308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224,
            483532, 504758};
    private int year;
    private int month;
    private int day;
    private boolean leap;
    final static String chineseNumber[] = {"正", "二", "三", "四", "五", "六", "七",
            "八", "九", "十", "十一", "腊"};
    final static String chineseNumber1[] = {"一", "二", "三", "四", "五", "六", "七",
            "八", "九", "十", "十一", "十二"};
    static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");

    public int newYear;
    public int newMonth;
    public int newDay;
    String cY = null;
    String cM = null;
    String cD = null;
    String cH = null;

    public Birth(Calendar cal) {
        newYear = cal.get(Calendar.YEAR);
        newMonth = cal.get(Calendar.MONTH) + 1;
        newDay = cal.get(Calendar.DATE);
        int leapMonth = 0;
        Date baseDate = null;
        try {
            baseDate = chineseDateFormat.parse("1900年1月31日");
        } catch (ParseException e) {
            e.printStackTrace(); // To change body of catch statement use
            // Options | File Templates.
        }

        // 求出和1900年1月31日相差的天数
        int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);

        // 用offset减去每农历年的天数
        // 计算当天是农历第几天
        // i最终结果是农历的年份
        // offset是当年的第几天
        int iYear, daysOfYear = 0;
        for (iYear = 1900; iYear < 2100 && offset > 0; iYear++) {
            daysOfYear = lYearDays(iYear);
            offset -= daysOfYear;
        }
        if (offset < 0) {
            offset += daysOfYear;
            iYear--;
        }
        // 农历年份
        year = iYear;
        leapMonth = leapMonth(iYear); // 闰哪个月,1-12
        leap = false;
        // 用当年的天数offset,逐个减去每月（农历）的天数，求出当天是本月的第几天
        int iMonth, daysOfMonth = 0;
        for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
            // 闰月
            if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
                --iMonth;
                leap = true;
                daysOfMonth = leapDays(year);
            } else
                daysOfMonth = monthDays(year, iMonth);

            offset -= daysOfMonth;
            // 解除闰月
            if (leap && iMonth == (leapMonth + 1))
                leap = false;
            if (!leap)
                ;
        }
        // offset为0时，并且刚才计算的月份是闰月，要校正
        if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
            if (leap) {
                leap = false;
            } else {
                leap = true;
                --iMonth;
            }
        }
        // offset小于0时，也要校正
        if (offset < 0) {
            offset += daysOfMonth;
            --iMonth;
        }
        month = iMonth;
        day = offset + 1;
    }

    public static String getChinaDayString(int day) {
        String chineseTen[] = {"初", "十", "廿", "卅"};
        int n = day % 10 == 0 ? 9 : day % 10 - 1;
        if (day > 30)
            return "";

        if (day == 10)
            return "初十";

        if (day == 20)
            return "二十";

        if (day == 30)
            return "三十";

        return chineseTen[day / 10] + chineseNumber1[n];
    }

    public Map toLunar() {
        String m = null;
        String d = getChinaDayString(day);
        if (leap) {
            m = "闰" + chineseNumber[month - 1] + "月";
        } else {
            m = chineseNumber[month - 1] + "月";
        }
        Map map = new HashMap();
        map.put("m", m);
        map.put("d", d);

        return map;

    }

    public String getChinaWeekdayString(String weekday) {
        if (weekday.equals("Mon"))
            return "一";
        if (weekday.equals("Tue"))
            return "二";
        if (weekday.equals("Wed"))
            return "三";
        if (weekday.equals("Thu"))
            return "四";
        if (weekday.equals("Fri"))
            return "五";
        if (weekday.equals("Sat"))
            return "六";
        if (weekday.equals("Sun"))
            return "日";
        else
            return "";

    }

    /**
     * 返回农历 y年的总天数
     *
     * @param y
     */
    public int lYearDays(int y) {
        int i, sum = 348;
        for (i = 0x8000; i > 0x8; i >>= 1) {
            sum += (lunarInfo[y - 1900] & i) > 0 ? 1 : 0;
        }
        return (sum + leapDays(y));
    }

    /**
     * 返回农历 y年闰月的天数
     *
     * @param y
     * @return
     */
    public int leapDays(int y) {
        if (leapMonth(y) > 0) {
            long day = lunarInfo[y - 1900] & 0x10000;
            return day > 0 ? 30 : 29;
        } else
            return 0;
    }

    /**
     * 返回农历 y年闰哪个月 1-12 , 没闰返回 0
     *
     * @param y
     * @return
     */
    public int leapMonth(int y) {
        return (lunarInfo[y - 1900] & 0xf);
    }

    /**
     * 返回农历 y年m月的总天数
     *
     * @param y
     * @param m
     * @return
     */
    public int monthDays(int y, int m) {
        return ((lunarInfo[y - 1900] & (0x10000 >> m)) > 0 ? 30 : 29);
    }

    final public String animalsYear() {
        final String[] Animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇",
                "马", "羊", "猴", "鸡", "狗", "猪"};
        return Animals[(year - 4) % 12];
    }

    // ===== 某年的第n个节气为几日(从0小寒起算) Date.UTC(1900, 0, 6, 2, 5)

    /**
     * 正确的立春时间应该是以小时来进行计算的
     *
     * @param y
     * @param n
     * @return
     */
    public int sTerm(int y, int n) {
        long times = 31556925974L * (y - 1900) + sTermInfo[n] * 60000L
                + (long) 0.7 * (y - 1900);
        Date offDate = new Date(times - 2208549300000L);
        // 1、取得本地时间：
        Calendar cal = Calendar.getInstance();
        cal.setTime(offDate);
        // 2、取得时间偏移量：
        int zoneOffset = cal.get(Calendar.ZONE_OFFSET);
        // 3、取得夏令时差：
        int dstOffset = cal.get(Calendar.DST_OFFSET);
        // 4、从本地时间里扣除这些差量，即可以取得UTC时间：
        cal.add(Calendar.MILLISECOND, -(zoneOffset + dstOffset));
        // 之后调用cal.get(int x)或cal.getTimeInMillis()方法所取得的时间即是UTC标准时间。
        return (cal.get(Calendar.DATE));
    }

    /**
     * 传入 offset 返回干支, 0=甲子
     *
     * @param num
     * @return
     */
    public String cyclical(int num) {
        return (Gan[num % 10] + Zhi[num % 12]);
    }

    /**
     * 计算 并 打印 八字
     *
     * @param date
     * @throws ParseException
     */
    public Map horoscope(String date) throws ParseException {
        Map resMap = new HashMap();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(date));
        int y = cal.get(Calendar.YEAR);
        int m = cal.get(Calendar.MONTH);
        int i = cal.get(Calendar.DATE) - 1;

        // 年柱 1900年立春后为庚子年(60进制36)
        if (m < 2) {
            cY = cyclical(y - 1900 + 36 - 1);
        } else {
            cY = cyclical(y - 1900 + 36);
        }
        int term2 = sTerm(y, 2); // 立春日期
        // 月柱 1900年1月小寒以前为 丙子月(60进制12)
        int firstNode = sTerm(y, m * 2); // 返回当月「节」为几日开始
        cM = cyclical((y - 1900) * 12 + m + 12);
        int dayCyclical = jlday(y, m);
        // 依节气调整二月分的年柱, 以立春为界
        if (m == 1 && (i + 1) >= term2)
            cY = cyclical(y - 1900 + 36);
        // 依节气月柱, 以「节」为界
        if ((i + 1) >= firstNode)
            cM = cyclical((y - 1900) * 12 + m + 13);
        // 日柱
        cD = cyclical(dayCyclical + i);

        // 时柱
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int hGIndex = hourG(cD.substring(0, 1), hour);
        //"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬","癸"
        // 4 9
        if (hGIndex==-1){
            LogUtils.d("异常 horoscope"+cD + ""+hGIndex);
            hGIndex = 0;
        }
        cH = Gan[hGIndex] + Zhi[hourZ(hour)];
        resMap.put("cY", cY + "年");
        resMap.put("cM", cM + "月");
        resMap.put("cD", cD + "日");
        resMap.put("cH", cH + "时");
        return resMap;
    }

    /**
     * 根据 日干 推算 时柱 根据提供的推算图来计算
     *
     * @param dG
     * @param hour
     * @return
     */
    public int hourG(String dG, int hour) {
        int ind = 1;
        for (String s : Gan) {
            if (s.equals(dG)) {
                break;
            }
            ind++;
        }
        //甲子，乙丑，丙寅，丁卯，戊辰，己巳，庚午，辛未，壬申，癸酉，
        //甲戌，乙亥，丙子，丁丑，戊寅，己卯，庚辰，辛巳，壬午，癸未，
        //甲申、乙酉，丙戌，丁亥，戊子，己丑，庚寅，辛卯，壬辰，癸巳，
        //甲午，乙未，丙申，丁酉，戊戌，己亥，庚子，辛丑，壬寅，癸卯，
        //甲辰，乙巳，丙午，丁未，戊申，己酉，庚戌，辛亥，壬子，癸丑，
        //甲寅，乙卯，丙辰，丁巳，戊午，己未，庚申，辛酉，壬戌，癸亥。
        //时干=日干×2+时支（晨子=-1，夜子=11）
        ind = ind % 5; // 五个为一周期
        int hourind = hourZ(hour);
        if (ind == 0) {
            ind = 5;
        }
        return (hourind + 2 * (ind - 1)) % 10;
//
//        if (hourind > 10)
//            return hourind - 10 + (ind - 1) * 2;
//        else {
//            hourind = hourind + (ind - 1) * 2;
//            return hourind >= 10 ? hourind - 10 : hourind;
//        }
    }

    /**
     * 返回 小时对应的 支的索引
     *
     * @param hour
     * @return
     */
    public static int hourZ(int hour) {
        if (hour >= 23 || hour < 1)
            return 0;
        else if (hour < 3)
            return 1;
        else if (hour < 5)
            return 2;
        else if (hour < 7)
            return 3;
        else if (hour < 9)
            return 4;
        else if (hour < 11)
            return 5;
        else if (hour < 13)
            return 6;
        else if (hour < 15)
            return 7;
        else if (hour < 17)
            return 8;
        else if (hour < 19)
            return 9;
        else if (hour < 21)
            return 10;
        else
            return 11;
    }

    /**
     * 间隔天数
     *
     * @param y
     * @param m
     * @return
     */
    public int jlday(int y, int m) {
        Calendar instance = Calendar.getInstance();
        instance.set(y, m, 1, 0, 0, 0);
        long res = (instance.getTimeInMillis() + 8 * 60 * 60 * 1000) / 86400000 + 25567 + 10;
        return (int) res;
    }

    public static void main(String[] args) throws ParseException {
        Calendar today = Calendar.getInstance();
        Date date = new Date();
        today.setTime(date);//加载当前日期
        Birth birth = new Birth(today);
        Map resMap = new HashMap();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
        Map lunar = birth.toLunar();//计算输出阴历日期
        String animalsYear = birth.animalsYear() + "年";//计算输出属相
        String dayTime = sdf.format(date);//输出阳历日期
        String weekDay =
                "星期" + birth.getChinaWeekdayString(today.getTime().toString().substring(0, 3));
        //计算输出星期几
        Map map = birth.horoscope(dayTime);
        Object cY = map.get("cY");
        Object cM = map.get("cM");
        Object cD = map.get("cD");
        Object cH = map.get("cH");
        resMap.put("lunar", lunar);
        resMap.put("animalsYear", animalsYear);
        resMap.put("dayTime", dayTime);
        resMap.put("weekDay", weekDay);
        resMap.put("cY", cY);
        resMap.put("cM", cM);
        resMap.put("cD", cD);
        resMap.put("cH", cH);
        System.out.println(resMap);
    }

    public String getcY() {
        return cY;
    }

    public String getcM() {
        return cM;
    }

    public int getYear() {
        return year;
    }

    public int getMonth() {
        return month;
    }

    public int getDay() {
        return day;
    }

    public String getcD() {
        return cD;
    }

    public String getcH() {
        return cH;
    }

    public int getNewYear() {
        return newYear;
    }

    public int getNewMonth() {
        return newMonth;
    }

    public int getNewDay() {
        return newDay;
    }


    //二十四节气
    final static String[] solarTerms = new String[]{"小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏",
            "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"};
    //二十四节气日期偏移度
    private static final double D = 0.2422;
    //特殊年份节气日期偏移
    private final static Map<Integer, Integer[]> INCREASE_OFFSETMAP = new HashMap<Integer, Integer[]>();//+1偏移
    private final static Map<Integer, Integer[]> DECREASE_OFFSETMAP = new HashMap<Integer, Integer[]>();//-1偏移

    static {
        INCREASE_OFFSETMAP.put(0, new Integer[]{1982});//小寒
        DECREASE_OFFSETMAP.put(0, new Integer[]{2019});//小寒
        INCREASE_OFFSETMAP.put(1, new Integer[]{2082});//大寒
        DECREASE_OFFSETMAP.put(3, new Integer[]{2026});//雨水
        INCREASE_OFFSETMAP.put(5, new Integer[]{2084});//春分
        INCREASE_OFFSETMAP.put(9, new Integer[]{2008});//小满
        INCREASE_OFFSETMAP.put(10, new Integer[]{1902});//芒种
        INCREASE_OFFSETMAP.put(11, new Integer[]{1928});//夏至
        INCREASE_OFFSETMAP.put(12, new Integer[]{1925, 2016});//小暑
        INCREASE_OFFSETMAP.put(13, new Integer[]{1922});//大暑
        INCREASE_OFFSETMAP.put(14, new Integer[]{2002});//立秋
        INCREASE_OFFSETMAP.put(16, new Integer[]{1927});//白露
        INCREASE_OFFSETMAP.put(17, new Integer[]{1942});//秋分
        INCREASE_OFFSETMAP.put(19, new Integer[]{2089});//霜降
        INCREASE_OFFSETMAP.put(20, new Integer[]{2089});//立冬
        INCREASE_OFFSETMAP.put(21, new Integer[]{1978});//小雪
        INCREASE_OFFSETMAP.put(22, new Integer[]{1954});//大雪
        DECREASE_OFFSETMAP.put(23, new Integer[]{1918, 2021});//冬至
    }

    //定义一个二维数组，第一维数组存储的是20世纪的节气C值，第二维数组存储的是21世纪的节气C值,0到23个，依次代表立春、雨水...大寒节气的C值
    private static final double[][] CENTURY_ARRAY = {
            {6.11, 20.84, 4.6295, 19.4599, 6.3826, 21.4155, 5.59, 20.888, 6.318, 21.86, 6.5, 22.2, 7.928, 23.65, 8.35
                    , 23.95, 8.44, 23.822, 9.098, 24.218, 8.218, 23.08, 7.9, 22.6},
            {5.4055, 20.12, 3.87, 18.73, 5.63, 20.646, 4.81, 20.1, 5.52, 21.04, 5.678, 21.37, 7.108, 22.83, 7.5,
                    23.13, 7.646, 23.042, 8.318, 23.438, 7.438, 22.36, 7.18, 21.94}
    };

    static Set<String> jieQiSet = new TreeSet<>(Arrays.asList(
            "立春" ,
            "惊蛰" ,
            "清明" ,
            "立夏" ,
            "芒种" ,
            "小暑" ,
            "立秋" ,
            "白露" ,
            "寒露" ,
            "立冬" ,
            "大雪" ,
            "小寒"));
  static   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    static SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static LunarTerm getTargetLunarTerm(int offset,long time) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        long firstTimeInMillis = calendar.getTimeInMillis();
        int tY, tM, tD;
        int count = 0;
        int preCount = 0;
        //、、、、、、、、、、、
        long timestamp = 0;
        do {
            tY = calendar.get(Calendar.YEAR);
            tM = calendar.get(Calendar.MONTH);
            tD = calendar.get(Calendar.DATE);
            boolean hasFind = false;
            String dayStr = format.format(calendar.getTime());
            TermModel model = DataUtils.getTeamModel(dayStr);
            if (model != null && jieQiSet.contains(model.getName())) {
                try {
                    Date date = format1.parse(model.getTime());
                    //当前时间大于节气的时间
                    timestamp = date.getTime();
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
                if (count == 0){
                    //判断当前时间戳
                    boolean isNew = time < timestamp;
                    if (!isNew ) {
                        hasFind = offset < 0;
                    } else  {
                        hasFind = offset > 0;
                    }
                }else {
                    hasFind = true;
                }
                if (hasFind){
                    double aa = Math.abs(timestamp - firstTimeInMillis) / (1000*60*12d);
                    int offsetDay = (int) Math.round(aa);
                    return new LunarTerm(model.getName(), tY, tM + 1, tD, timestamp, offsetDay,model.getTime());
                }
            }
            calendar.add(Calendar.DATE, offset);
            count++;
        } while (count <= 60);
        return null;
    }

    /**
     * 获取某年的第n个节气为几日(从0小寒起算)
     *
     * @param year
     * @param n
     * @return
     */
    private static int sTerm1(int year, int n) {
        double centuryValue = 0;//节气的世纪值，每个节气的每个世纪值都不同
        int centuryIndex = -1;
        if (year >= 1901 && year <= 2000) {//20世纪
            centuryIndex = 0;
        } else if (year >= 2001 && year <= 2100) {//21世纪
            centuryIndex = 1;
        } else {
            throw new RuntimeException("不支持此年份：" + year + "，目前只支持1901年到2100年的时间范围");
        }
        centuryValue = CENTURY_ARRAY[centuryIndex][n];
        int dateNum = 0;

        int y = year % 100;//步骤1:取年分的后两位数
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {//闰年
            if (n == 0 || n == 1 || n == 2 || n == 3) {
                //注意：凡闰年3月1日前闰年数要减一，即：L=[(Y-1)/4],因为小寒、大寒、立春、雨水这两个节气都小于3月1日,所以 y = y-1
                y = y - 1;//步骤2
            }
        }
        dateNum = (int) (y * D + centuryValue) - (int) (y / 4);//步骤3，使用公式[Y*D+C]-L计算
        dateNum += specialYearOffset(year, n);//步骤4，加上特殊的年分的节气偏移量
        return dateNum;
    }

    /**
     * 特例,特殊的年分的节气偏移量,由于公式并不完善，所以算出的个别节气的第几天数并不准确，在此返回其偏移量
     *
     * @param year 年份
     * @param n    节气编号
     * @return 返回其偏移量
     */
    private static int specialYearOffset(int year, int n) {
        int offset = 0;
        offset += getOffset(DECREASE_OFFSETMAP, year, n, -1);
        offset += getOffset(INCREASE_OFFSETMAP, year, n, 1);
        return offset;
    }

    /**
     * 节气偏移量计算
     *
     * @param map
     * @param year
     * @param n
     * @param offset
     * @return
     */
    private static int getOffset(Map<Integer, Integer[]> map, int year, int n, int offset) {
        int off = 0;
        Integer[] years = map.get(n);
        if (null != years) {
            for (int i : years) {
                if (i == year) {
                    off = offset;
                    break;
                }
            }
        }
        return off;
    }
    public static class LunarTerm {
        private String term;
        private int year;
        private int month;
        private int day;

        private long timeMillis;
        private String timeStr;
        int offsetDay;


        public LunarTerm(String term, int year, int month, int day,long timeMillis,int offsetDay,String timeStr) {
            this.term = term;
            this.year = year;
            this.month = month;
            this.day = day;
            this.timeMillis = timeMillis;
            this.timeStr = timeStr;
            this.offsetDay = offsetDay;
        }

        public int getOffsetDay() {
            return offsetDay;
        }

        public long getTimeMillis() {
            return timeMillis;
        }

        public String getTerm() {
            return term;
        }

        public int getYear() {
            return year;
        }

        public int getMonth() {
            return month;
        }

        public int getDay() {
            return day;
        }

        @Override
        public String toString() {
            return term + "(" + timeStr+ ')';
        }
    }
}
